import os
import time
from functools import wraps

def make_dir(path):
    path = path.strip()
    path = path.rstrip("\\")
    isExists = os.path.exists(path)
    if not isExists:
        os.makedirs(path)
        return True
    else:
        print(path + ' already exists.')
        return False


class Timer:
    def __init__(self):
        self.__start = time.time()
        self.__elapsed = None

    def reset(self):
        self.__start = time.time()

    def count(self):
        self.__elapsed = time.time() - self.__start
        print(f'elapsed: {self.__elapsed}s.')

def timer(func):
    """
    a timer count the time for running functions
    :param func: target function
    :return:
    """
    @wraps(func)
    def wrapped(*args, **kwargs):
        start_time = time.time()
        result = func(*args, **kwargs)
        elapsed = time.time() - start_time
        print("func<{}> time cost -> {}s".format(func.__name__, elapsed))
        return result

    return wrapped


def getDate():
    return time.strftime("%Y-%m-%d", time.localtime())


